{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Examples and Exercises from Think Stats, 2nd Edition\n",
    "\n",
    "http://thinkstats2.com\n",
    "\n",
    "Copyright 2016 Allen B. Downey\n",
    "\n",
    "MIT License: https://opensource.org/licenses/MIT\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import print_function, division\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "import nsfg\n",
    "import first\n",
    "import thinkstats2\n",
    "import thinkplot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Again, I'll load the NSFG pregnancy file and select live births:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "preg = nsfg.ReadFemPreg()\n",
    "live = preg[preg.outcome == 1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's the histogram of birth weights:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEKCAYAAAAFJbKyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAHWBJREFUeJzt3X+cVXW97/HX2+HHaGAioBeBGlQ0DZVwFBL1+uNYaJ7I1MJTSF070zXtx6m8aXY1O3ov99Yp61gWKkc8KRw0KzRNyTDkHOKHiAiSx0kRJrgyihhGktDn/rG+g9thz8xew+zZe+D9fDz2Y6/92Wut/dkDM++9fuzvUkRgZmZWqn0q3YCZmfUsDg4zM8vFwWFmZrk4OMzMLBcHh5mZ5eLgMDOzXBwcZmaWi4PDzMxycXCYmVkuvSrdQDkM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uTg4zMwsFweHmZnl4uAwM7NcHBxmZpaLg8PMzHL5/9Sesj4iouyOAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "hist = thinkstats2.Hist(live.birthwgt_lb, label='birthwgt_lb')\n",
    "thinkplot.Hist(hist)\n",
    "thinkplot.Config(xlabel='Birth weight (pounds)', ylabel='Count')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To normalize the disrtibution, we could divide through by the total count:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = hist.Total()\n",
    "pmf = hist.Copy()\n",
    "for x, freq in hist.Items():\n",
    "    pmf[x] = freq / n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The result is a Probability Mass Function (PMF)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAHZ9JREFUeJzt3X+8VXW95/HX28OPo6GFcG5X+SGgYBIq6hEolZsmhT8GKrWgNJyxB2lR3uutEUcHk6sz3Jzp2h1sEo2RbgqpdRsyTMkwYELkqAiCkUckOBcnkR9KoujBz/1jrUPbzT57nQNnnb2T9/Px2A/W+q71XfuzgXPee/36LkUEZmZm5RxS6QLMzKz6OSzMzCyTw8LMzDI5LMzMLJPDwszMMjkszMwsk8PCzMwy5RoWksZKWiepUdLUEsuvlLRa0kpJSyUNTdsHSHojbV8p6ft51mlmZuUpr5vyJNUAv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1atHf5qFGjeOaZZxg9ejR33nknNTU1DBkyhLVr17J06VJOO+00lixZwu7du2lqauK4447jpptu4pxzzuGpp57i05/+NBs3bgRgxowZHHvssaxcuZJbb721TZ/hiSee4J577mHlypXcf//9HT6wqsPCzA56/fr144wzzgDg0ksvZenSpe9aXlNTw0UXXdRq/27dunHhhRcCcNppp7FhwwYg2YNYvHgxixcv5rrrrmPp0qWsWLGC008/HYClS5cyYcIEAMaOHUvPnj33+zOMGTOGXr16ceihh/KZz3xmn89woBwWZnbQK74HoXi+traWmpqaVvt37dp1b5+amhqam5uBJCyWLFnCE088wfnnn8+OHTt47LHHGD16NJDcWd1Zn+FA+WooM6salbpybOPGjSxbtoyPfOQjzJ07lzPPPJOf//znra5/+OGHs3PnTnr37l12uyNHjuSLX/wigwYNora2luHDh3PHHXfw4IMPAnDmmWdy3333ce211/LII4+wffv2d22/PRYuXMi2bds49NBD+dnPfsbs2bPb1T+L9yzM7KB3wgknMGfOHE466SS2bdvGVVddVXb9yZMnc955573rBHcp3bt3p1+/fowaNQpI9jR27tzJiSeeCMCNN97II488wqmnnspDDz3EUUcdtXesrDPOOINhw4a1+QT3mWeeyWWXXcbw4cO56KKLqK/PHO6pXTyQoFkZvs8iX8899xwnnHBCpcuomN27d1NTU0OXLl1YtmwZV111FStXrszt/Ur9fbd1IEEfhjIzq5CNGzfy2c9+lnfeeYdu3bpx5513VrqkVjkszMwqZPDgwTz99NNl11m9ejWXXXbZu9q6d+/O8uXL8yxtHw4LM6uoiPDIs2WceOKJHXJo6kBPOfgEt5lVTG1tLVu3bu3QS0htXy0PP6qtrd3vbXjPwswqpm/fvjQ1NbFly5ZKl/Ke1/JY1f3lsDCziunates+j/m06uTDUGZmlslhYWZmmRwWZmaWKdewkDRW0jpJjZKmllh+paTVklZKWippaMGy69J+6yR9Ms86zcysvNzCQlINcDtwHjAUmFgYBql7I+LEiBgOfBv4Ttp3KDAB+DAwFvheuj0zM6uAPPcsRgCNEbE+It4C5gHjC1eIiNcK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+DvK12EdS7vWZiZWSafszAzs0wOCzMzy+SwMDOzTA4LMzPL5LAwM7NMDgszM8v071he8h+dPnffAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "thinkplot.Hist(pmf)\n",
    "thinkplot.Config(xlabel='Birth weight (pounds)', ylabel='PMF')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "More directly, we can create a Pmf object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Pmf({1: 0.2, 2: 0.4, 3: 0.2, 5: 0.2})"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pmf = thinkstats2.Pmf([1, 2, 2, 3, 5])\n",
    "pmf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Pmf` provides `Prob`, which looks up a value and returns its probability:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pmf.Prob(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The bracket operator does the same thing."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pmf[2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `Incr` method adds to the probability associated with a given values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6000000000000001"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pmf.Incr(2, 0.2)\n",
    "pmf[2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `Mult` method multiplies the probability associated with a value."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.30000000000000004"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pmf.Mult(2, 0.5)\n",
    "pmf[2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Total` returns the total probability (which is no longer 1, because we changed one of the probabilities)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8999999999999999"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pmf.Total()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Normalize` divides through by the total probability, making it 1 again."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pmf.Normalize()\n",
    "pmf.Total()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's the PMF of pregnancy length for live births."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "pmf = thinkstats2.Pmf(live.prglngth, label='prglngth')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's what it looks like plotted with `Hist`, which makes a bar graph."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png":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MYJRUg+1/Aa11AMo9E1FMxTwN4RcSVwJ/CThrYvUPxbaztnKKg/vZaZ0xoXlB82/69xEcW3zVnd2h3YZN2NY9u8BQwvx8M5Fjg8M1+NiHsotjgA3szMbGzfZP3fp/jW/vvAdU3aBvDlzLymWx/aeqhzFD0P99ybd/W1hzabImKHzPxdZr4ZxUiiZ1N8838Y+CjwEYrB8j5Cz+/5/sCqzDx8M3X8AvhoRHw9Mzdm5osRcQDwp8BngX8DnFO2HQm8toX91DbIYwoaaCuAIyNiH4CI+L2I+APgCYpvoW1lu9N6fvo77Aa8WAbCZIpvxM3cRbFbq+tmNV1n7/yI4hamhwBLm6xjKXBOw375PaMY/75Hmfki8EoUt82EYsTPLq8Ao/tQd3ergb0b5n8OfK78fS/FQf6HymDc3Hu+GhgXEYeXy0dExB81rPNaYAlwS0QMj4ixwA6ZeRvwd8BBDW3/gGIXmbZzhoIGVGauo/hGvigiHqb4wJqcma8B/x74x4hYRjG668tNVvePFFsMDwOXl+tq5gKKb7+PUOx2+aOyrjcohmS+udyt1FsffkKxC2h5uZ5baf7B/ilgQUQsp9hy6Orb3RQHlhsPNPfFnRQj4Xa5F9gDWJ6ZzwMby2W9vedvUAxB/dWI+BXwEHBEt75+g2J31A8o7nB2T7mLcCFwMVT3s9gH6NiC+rWNcpRUbTMiYpfM3BDFPqergScz85sD9No7UHz4nZqZT9aw/l2yvLdyRFwE7JGZFzR5Wm/r2wP4r5l5XNPGNSuP6RyUmX832LVo67mloG3Jp8tvoasodg1d06R9v4iIKcAa4K46AqF0Urk18CjFAeArtmZlWdyr93tR08VrW2g48PXBLkL9wy0FSVLFLQVJUsVQkCRVDAVJUsVQkCRVDAVJUsVQkCRV/j+4uJW9DB43JAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "thinkplot.Hist(pmf)\n",
    "thinkplot.Config(xlabel='Pregnancy length (weeks)', ylabel='Pmf')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's what it looks like plotted with `Pmf`, which makes a step function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAGkZJREFUeJzt3X2UFPWd7/H3R54XZ00CmPUKOMSHKGsEoVWerpsQkwvRwK7RxadzdfWE4IajubvJBu/uGq9uTkxiknUVz0rEo+aq+LRZSYTVHB9udAMJo/iEyIZLEGfxKOJD8CoPY773j6qptE3PdA90dc/0fF7ncKaq+tfV32rb/nT9qupXigjMzMwADmh0AWZm1ns4FMzMLONQMDOzjEPBzMwyDgUzM8s4FMzMLONQMDOzjEPBzMwyDgUzM8sMbHQBPTVy5MhobW1tdBlmZn3Kk08++XpEjKrUrs+FQmtrK21tbY0uw8ysT5H0UjXt3H1kZmYZh4KZmWUcCmZmlulzxxTK2bNnD+3t7ezcubPRpfQpQ4cOZfTo0QwaNKjRpZhZL9EUodDe3k5LSwutra1IanQ5fUJEsH37dtrb2xk3blyjyzGzXqIpuo927tzJiBEjHAg9IIkRI0Z478rMPqApQgFwIOwDv2dmVqopuo/MrO+7/5FnuGtlG7t279nrsSGDBzFvdoG5Myc0oLL+pWn2FPq6xx57jNNOO22fn3/LLbewdevWbL61tZXXX3+9FqWZ1UVXgQCwa/ce7lrpi1brwaFQR++//35u6y4NBbO+pqtAqPZxq41cu48kzQKuBQYAN0XE1SWPXwB8F/jPdNH1EXFTnjXlZfPmzcyaNYuTTjqJtWvXctRRR3Hbbbcxfvx4LrzwQh566CEWLlzI4YcfzkUX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DnwIVp26HAez3cTuuFfEzB6m01MF3SEQCS/kDSUcCLJL9CW9N288o//QMOAt5MA+Fokl/ElTxM0q3VebOazrN3fkxyC9MTgAcrrONB4MKifvlDlYx/X1ZEvAnsUHLbTEhG/Oy0A2ipou5SG4CPFc3/HPhq+vdxkoP8T6fB2NV7vgEYJWlqunyQpD8uWudSYAVwj6SBkkYCB0TEfcDfA5OK2h5F0kVmfZxDweoqIraR/CK/U9KzJF9YR0fEe8BfAv8m6QmS0V3frrC6fyPZY3gWuCpdVyWXkvz6fY6k2+WP07p2kwzJfHfardTdNjxE0gW0Kl3PvVT+Yr8IWCJpFcmeQ+e2PUpyYLn4QHM1HiAZCbfT48AhwKqIeBXYmS7r7j3fTTIE9bclPQM8DUwr2dbvk3RH/YjkDmePpV2EtwCXQXY/iyOAth7Ub72UR0m1XkPSgRHxjpI+p8XAryPiB3V67QNIvvzOjIhf57D+AyO9t7KkRcAhEXFphad1t75DgNsi4jMVG+csPaYzKSL+vtG12P7znoL1Jl9Mf4WuI+kaurFC+5qQNB7YCDycRyCkTk33Bp4nOQD8D/uzskju1ftD5XTxWg8NBL7X6CKsNrynYGZmGe8pmJlZxqFgZmYZh4KZmWUcCmZmlnEomJlZxqFgZmaZ/w/H5uhdYRXu4gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "thinkplot.Pmf(pmf)\n",
    "thinkplot.Config(xlabel='Pregnancy length (weeks)', ylabel='Pmf')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use `MakeFrames` to return DataFrames for all live births, first babies, and others."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "live, firsts, others = first.MakeFrames()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here are the distributions of pregnancy length."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "first_pmf = thinkstats2.Pmf(firsts.prglngth, label='firsts')\n",
    "other_pmf = thinkstats2.Pmf(others.prglngth, label='others')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And here's the code that replicates one of the figures in the chapter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtQAAAF3CAYAAACFTdwtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3Xu8XHV97//XJ3snJCBHIckpl2C5yFWpEVIuBj0ekJtoOPUG2lpStTzUInj4HU+x9MGv0p8ebKtyeAgitSj9cRCs1hoVBS+ggQNIIogJ4ZLEKPvHaQ2RWCKXXPj8/piVMGz27J3Md9aemb1fz8djP1izZq01n1lZ+8N7f2fNWpGZSJIkSWrPlG4XIEmSJPUzA7UkSZJUwEAtSZIkFTBQS5IkSQUM1JIkSVIBA7UkSZJUoNZAHRGnRMSDEbEyIi5osczbI+L+iFgeEdfVWY8kqTV7tiS1J+q6DnVEDAAPAScCQ8DdwDsy8/6mZQ4Evgwcn5mPR8R/zMxf1VKQJKkle7Ykta/OEeqjgJWZuTozNwLXA6cPW+ZPgcsz83EAG7MkdY09W5LaVGeg3ht4pOnxUDWv2UHAQRFxe0TcGRGn1FiPJKk1e7YktWmwxm3HCPOGn18yCBwIvA6YAyyOiFdk5vrnbSjibOBsgF122eXIQw45pPPVSlLNli5d+lhmzu52HS3YsyVpmO3t23UG6iFgn6bHc4BHR1jmzszcBPw8Ih6k0azvbl4oM68CrgKYN29eLlmypLaiJakuEfGLbtcwCnu2JA2zvX27zlM+7gYOjIj9ImIacCawaNgy/wL8Z4CImEXj48TVNdYkSRqZPVuS2lRboM7MzcA5wE3ACuDLmbk8Ii6OiAXVYjcB6yLifuAW4MOZua6umiRJI7NnS1L7artsXl38+FBSv4qIpZk5r9t1jCd7tqR+tr19u85zqCVNMps2bWJoaIinn36626V01fTp05kzZw5Tp07tdimS1JI9+zmlfdtALaljhoaG2HXXXdl3332JGOmiERNfZrJu3TqGhobYb7/9ul2OJLVkz27oRN+u9dbjkiaXp59+mpkzZ07qxhwRzJw50xEfST3Pnt3Qib5toJbUUZO9MYP7QFL/sF81lO4HA7WkCeWyyy7j0EMPZbfdduOSSy7Z7vXWrFnDddddV2NlkqThJkrP9hxqSbU557O3dXR7n3n/cWMuc8UVV/Dtb3+75XlwmzdvZnDwha1va3N+5zvfWVynJGn7TJSebaCWNGG8733vY/Xq1SxYsIB3v/vdrFq1is985jMsXLiQ3XffnXvuuYcjjjiCBQsWcN555wGNj/l+9KMfccEFF7BixQrmzp3LWWedxUknncSf/MmfsHHjRp599lm++tWvcuCBB3b5HUrSxDGReraBWtKEceWVV/Kd73yHW265hW9+85vPe+6hhx7ie9/7HgMDA7zpTW/i8ssvZ/78+WzYsIHp06dzySWX8Hd/93fb1vvgBz/Ieeedxx/+4R+yceNGtmzZ0o23JEnj4i0fv7m2bX/1L04acf5E6tmeQy1pUnjb297GwMAAAPPnz+f888/nsssuY/369SN+nHjsscfy8Y9/nE984hP84he/YMaMGeNdsiRNWv3Wsw3UkiaFXXbZZdv0BRdcwOc//3meeuopjjnmGB544IEXLP/Od76TRYsWMWPGDE4++WR+8IMfjGe5kjSp9VvP9pQPSZPOqlWrOPzwwzn88MO54447eOCBB9hnn3144oknti2zevVq9t9/f84991xWr17Nfffdx/HHH9/FqiWpPq1Oy+gF/dCzDdSSJp1LL72UW265hYGBAQ477DBOPfVUpkyZwuDgIK985StZuHAhTz/9NNdeey1Tp05ljz324KKLLup22ZI0KfVDz47MHNcXLDVv3rxcsmRJt8uQNIIVK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75LrBnq/0/7HU+BEyPiL8BDgd+XH3UeCGw9cszv0NjdOv/jFGzpD5mz7Znqz7x3KcyUudExIsyc0P10dflwMOZ+elxeu0pNBrc2zLz4Rq2/6LM3FBNX0CjUZ43xmrDt/Eq4PzMfFen69tREfFfgX/PzH8Yc2FJE5I9e8xt2LM1KkeoVZc/rf6qXk7jo8HPjbF8R1RfElkJfL+Oxlw5rRrRWAa8hmrUYEdk5j3ALVHTTQJ20Hrgmm4XIamr7NmjsGdrLI5QS5IkSQUcoZYkSZIKGKglSZKkAgZqSZIkqYCBWpIkSSpgoJYkSZIKGKglSZKkAv8/wLmFxCH8M6YAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 864x432 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "width=0.45\n",
    "axis = [27, 46, 0, 0.6]\n",
    "thinkplot.PrePlot(2, cols=2)\n",
    "thinkplot.Hist(first_pmf, align='right', width=width)\n",
    "thinkplot.Hist(other_pmf, align='left', width=width)\n",
    "thinkplot.Config(xlabel='Pregnancy length(weeks)', ylabel='PMF', axis=axis)\n",
    "\n",
    "thinkplot.PrePlot(2)\n",
    "thinkplot.SubPlot(2)\n",
    "thinkplot.Pmfs([first_pmf, other_pmf])\n",
    "thinkplot.Config(xlabel='Pregnancy length(weeks)', axis=axis)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's the code that generates a plot of the difference in probability (in percentage points) between first babies and others, for each week of pregnancy (showing only pregnancies considered \"full term\"). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEKCAYAAAASByJ7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHR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Bp2dMD6bdRL8Bjhk6CI2OLQRJEmALQZLUmBAkSYAJQZLUmBAkSYAJQZLUmBAkSQD8f0lKzwL14HRZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "weeks = range(35, 46)\n",
    "diffs = []\n",
    "for week in weeks:\n",
    "    p1 = first_pmf.Prob(week)\n",
    "    p2 = other_pmf.Prob(week)\n",
    "    diff = 100 * (p1 - p2)\n",
    "    diffs.append(diff)\n",
    "\n",
    "thinkplot.Bar(weeks, diffs)\n",
    "thinkplot.Config(xlabel='Pregnancy length(weeks)', ylabel='Difference (percentage points)')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Biasing and unbiasing PMFs\n",
    "\n",
    "Here's the example in the book showing operations we can perform with `Pmf` objects.\n",
    "\n",
    "Suppose we have the following distribution of class sizes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "d = { 7: 8, 12: 8, 17: 14, 22: 4, \n",
    "     27: 6, 32: 12, 37: 8, 42: 3, 47: 2 }\n",
    "\n",
    "pmf = thinkstats2.Pmf(d, label='actual')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This function computes the biased PMF we would get if we surveyed students and asked about the size of the classes they are in."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "def BiasPmf(pmf, label):\n",
    "    new_pmf = pmf.Copy(label=label)\n",
    "\n",
    "    for x, p in pmf.Items():\n",
    "        new_pmf.Mult(x, x)\n",
    "        \n",
    "    new_pmf.Normalize()\n",
    "    return new_pmf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following graph shows the difference between the actual and observed distributions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {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iEGDBnHjjTcCpT/ukydPprq6mgkTJrBpU2mm6GnTpjFw4ECqq6t3jj5bX1/POeecw5AhQxgyZAi//e1vAfjWt77FlClTGD16NF/+8pcZNmwYy5Yt23neUaNGsWTJEv72t79x4YUXMmTIEE444QTuu+8+AN577z0mTZpEdXU1EydO5L333mv1393f4DazdiXLOTX2NFfIkiVL+MlPfsIzzzxDRDBs2DBOPfVUXnrpJWbOnMnJJ5/MhRdeyI9+9CMuvPBC5s2bx4oVK5DEW2+9BcDUqVP56le/yogRI1i9ejVjxoxh+fLlO59/4cKFdOvWjRtuuIE5c+bw7W9/m9dff521a9dy0kknMX36dD796U8za9Ys3nrrLYYOHcrpp5/O7bffTvfu3Vm6dClLly7lxBNPbPVr45aFmVkLLFy4kM9//vMcfPDBHHLIIZx99tksWLCAI488kpNPPhmA888/n4ULF3LYYYfRtWtXLr74Yu699166d+8OwKOPPsrll1/O4MGDGTduHO+88w7vvvsuAOPGjaNbt24AnHfeefziF78AYM6cOZx77rkAPPzww1x33XUMHjyYUaNGsXnzZlavXs38+fM5//zzAaiurqa6urrVf3+3LMzMWiCi+alkm05UJImKigp+//vf89hjjzF79mxuueUWHn/8cXbs2MGiRYt2hkK5xsEFAY444gh69erF0qVLueeee7j99tt31jB37lw+/vGPp9bR2hwWZtau5DWt7MiRI7nggguYNm0aEcG8efO48847mTp1KosWLeKTn/wkd999NyNGjGDjxo1s2rSJz372swwfPpyjjz4agNGjR3PLLbfw9a9/HYDnnnuOwYMHN3u+SZMmcf311/P2229z3HGlueDGjBnDzTffzM0334wknn32WU444QRGjhzJXXfdxac+9SleeOGFDwxi2BrcDWVm1gInnngiF1xwAUOHDmXYsGFcfPHF9OjRg2OPPZY77riD6upqNmzYwGWXXca7777LmWeeSXV1Naeeeio33HADUJppr7a2lurqagYOHMhtt9222/NNmDCB2bNnc9555+1cd9VVV7Ft2zaqq6sZNGgQV111FQCXXXYZGzdupLq6muuvv56hQ4e2+u+v3TWt2puamppo7c8VmxVF+U3dv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zoIumSxhWShkg6tcl+HwJej4gdwD9TGtgPSR+lNMfC/6E0Wu6JSYvgoIiYC1wFnNj0pJL6R8QzEXE1sI5SaJS7DlgaEbPL1j0EXJa0Ykg+sXXwPv/mZi3kbijr8CIiJH0euFHSNGAz8Crwr012/REwV9K5lIbE/luyfhTwdUnbgI3AlynN1PYTSY1vyL7RzKl/kNz7EKV5kv8IlAfUFcCyZIY8KN3j+DFQBfwh+RRXPZ5C1NqAR501M7NU7oYyM7NUDgszM0vlsDAzs1QOCzMzS+WwMDOzVA4LMzNL5bAwM7NUDgszM0v1/wELMCu3G/o9wwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "biased_pmf = BiasPmf(pmf, label='observed')\n",
    "thinkplot.PrePlot(2)\n",
    "thinkplot.Pmfs([pmf, biased_pmf])\n",
    "thinkplot.Config(xlabel='Class size', ylabel='PMF')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The observed mean is substantially higher than the actual."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Actual mean 23.692307692307693\n",
      "Observed mean 29.123376623376625\n"
     ]
    }
   ],
   "source": [
    "print('Actual mean', pmf.Mean())\n",
    "print('Observed mean', biased_pmf.Mean())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we were only able to collect the biased sample, we could \"unbias\" it by applying the inverse operation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "def UnbiasPmf(pmf, label=None):\n",
    "    new_pmf = pmf.Copy(label=label)\n",
    "\n",
    "    for x, p in pmf.Items():\n",
    "        new_pmf[x] *= 1/x\n",
    "        \n",
    "    new_pmf.Normalize()\n",
    "    return new_pmf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can unbias the biased PMF:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Unbiased mean 23.69230769230769\n"
     ]
    }
   ],
   "source": [
    "unbiased = UnbiasPmf(biased_pmf, label='unbiased')\n",
    "print('Unbiased mean', unbiased.Mean())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And plot the two distributions to confirm they are the same."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAGO1JREFUeJzt3Xt033Wd5/HnmxBaa5GhbbxRMHWkXAq0Sqig3Ga4tB0uRRYUUYZRD132iCIsLAVXFMYZx9EVDyyjdqYFjjICAxa6WqhUuZSRSxNFaIFqxWpDORJaKFvXQlPe+8fv25LGNN+0zS+/X5rn45ycfu+/dz6nySuf7+XzjcxEkqTe7FLrAiRJ9c+wkCSVMiwkSaUMC0lSKcNCklTKsJAklTIsJEmlDAtJUinDQpJUatdaF9BfxowZk83NzbUuQ5IGlba2thczs6lsu50mLJqbm2ltba11GZI0qETE7/qynaehJEmlDAtJUinDQpJUaqe5ZiFp57Zhwwba29tZv359rUsZlIYPH87YsWNpbGzcrv0NC0mDQnt7O7vvvjvNzc1ERK3LGVQyk9WrV9Pe3s64ceO26xiehpI0KKxfv57Ro0cbFNshIhg9evQO9coMC0mDhkGx/Xa07TwNpS184+5nWLisg4118LbdhoDj92vi4mn717oUacizZ6Et1EtQAGzMSj3SYHP//ffzs5/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3oo2KTPHZWZPQST1K8NCgp8CwyLivE0LIuKwiDim23Z7AM9n5uvAOVQG9iMi3kXlHQv/SmW03PcVPYJdMvMO4AvA+7p/aET8ZWY+mplXAi9SCY2u/gl4IjNv6bJsAfDfil4MxR1bb97u71zqI09DacjLzIyIDwHfjIiZwHpgBfC5bpv+C3BHRJxJZUjsPxbLjwUujYgNwDrgb6m8qe2GiNj0B9nlPXz014prH0HlPcm/BLoG1CXA0uINeVC5xvFvQDPw8+Iurg58hagGgKPOSpJKeRpKklTKsJAklTIsJEmlDAtJUinDQpJUyrCQJJUyLCRJpQwLSVKp/w80Cp3P0ALAWgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "thinkplot.PrePlot(2)\n",
    "thinkplot.Pmfs([pmf, unbiased])\n",
    "thinkplot.Config(xlabel='Class size', ylabel='PMF')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pandas indexing\n",
    "\n",
    "Here's an example of a small DataFrame."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.792518</td>\n",
       "      <td>0.200374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.697067</td>\n",
       "      <td>0.067361</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.731358</td>\n",
       "      <td>-1.011806</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.440653</td>\n",
       "      <td>-0.980818</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1\n",
       "0  0.792518  0.200374\n",
       "1 -0.697067  0.067361\n",
       "2 -0.731358 -1.011806\n",
       "3  1.440653 -0.980818"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas\n",
    "array = np.random.randn(4, 2)\n",
    "df = pandas.DataFrame(array)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can specify column names when we create the DataFrame:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.792518</td>\n",
       "      <td>0.200374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-0.697067</td>\n",
       "      <td>0.067361</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.731358</td>\n",
       "      <td>-1.011806</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.440653</td>\n",
       "      <td>-0.980818</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B\n",
       "0  0.792518  0.200374\n",
       "1 -0.697067  0.067361\n",
       "2 -0.731358 -1.011806\n",
       "3  1.440653 -0.980818"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "columns = ['A', 'B']\n",
    "df = pandas.DataFrame(array, columns=columns)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also specify an index that contains labels for the rows."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>0.792518</td>\n",
       "      <td>0.200374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>-0.697067</td>\n",
       "      <td>0.067361</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>-0.731358</td>\n",
       "      <td>-1.011806</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>1.440653</td>\n",
       "      <td>-0.980818</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B\n",
       "a  0.792518  0.200374\n",
       "b -0.697067  0.067361\n",
       "c -0.731358 -1.011806\n",
       "d  1.440653 -0.980818"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = ['a', 'b', 'c', 'd']\n",
    "df = pandas.DataFrame(array, columns=columns, index=index)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Normal indexing selects columns."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    0.792518\n",
       "b   -0.697067\n",
       "c   -0.731358\n",
       "d    1.440653\n",
       "Name: A, dtype: float64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['A']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use the `loc` attribute to select rows."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    0.792518\n",
       "B    0.200374\n",
       "Name: a, dtype: float64"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['a']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you don't want to use the row labels and prefer to access the rows using integer indices, you can use the `iloc` attribute:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    0.792518\n",
       "B    0.200374\n",
       "Name: a, dtype: float64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`loc` can also take a list of labels."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>0.792518</td>\n",
       "      <td>0.200374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>-0.731358</td>\n",
       "      <td>-1.011806</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B\n",
       "a  0.792518  0.200374\n",
       "c -0.731358 -1.011806"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "indices = ['a', 'c']\n",
    "df.loc[indices]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you provide a slice of labels, `DataFrame` uses it to select rows."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>0.792518</td>\n",
       "      <td>0.200374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>-0.697067</td>\n",
       "      <td>0.067361</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>-0.731358</td>\n",
       "      <td>-1.011806</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B\n",
       "a  0.792518  0.200374\n",
       "b -0.697067  0.067361\n",
       "c -0.731358 -1.011806"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['a':'c']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you provide a slice of integers, `DataFrame` selects rows by integer index."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>0.792518</td>\n",
       "      <td>0.200374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>-0.697067</td>\n",
       "      <td>0.067361</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B\n",
       "a  0.792518  0.200374\n",
       "b -0.697067  0.067361"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[0:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But notice that one method includes the last elements of the slice and one does not.\n",
    "\n",
    "In general, I recommend giving labels to the rows and names to the columns, and using them consistently."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Exercises"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Exercise:** Something like the class size paradox appears if you survey children and ask how many children are in their family. Families with many children are more likely to appear in your sample, and families with no children have no chance to be in the sample.\n",
    "\n",
    "Use the NSFG respondent variable `numkdhh` to construct the actual distribution for the number of children under 18 in the respondents' households.\n",
    "\n",
    "Now compute the biased distribution we would see if we surveyed the children and asked them how many children under 18 (including themselves) are in their household.\n",
    "\n",
    "Plot the actual and biased distributions, and compute their means."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "resp = nsfg.ReadFemResp()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution\n",
    "\n",
    "pmf = thinkstats2.Pmf(resp.numkdhh, label='numkdhh')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5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AFgFnET9CeYTMnMR9Vczf7ipXTfwTuqvbb41ImZRP7L/WWaeBpwG/GFEzGu0XwRcl5nzmzcWEW8FbgQWAwuB0yLi/My8AegFLs7MPxr0nR7gfOD0zFwA3NS0eFqj3quAT7TY1y8AX2rU+5NBy0q9EfF2YAX1F7YtBN4ALm60Owx4slHH48AfttimJglDQeNO4y2mdwMH03WyvjF2wi7gfwDfbsx/lnoQDHggM/dm5gvAi8C/of6+mn/XeC31OuAo4PhG++9n5v8cYnunAY9l5vbGK07+Cmj1dswlwB2Z+f8a+9k8ZsXAi/o2DKp3KGcC9zY+3zNoWXO97wJOBdY39u1dwK82lu0GBs5CDmSbmiSmtbsAaT/+HHgKuKNpXj+NA5nGi+5mNC3b1fR5b9P0Xt78//ng97ok9deefzgzH21eEBFnA/+8n/qGelV6KzHE9gcM1PsGB/bvcn/raa43gLsy8+NDtNuTv3jHzYFuU5OAZwoalxpH0Q9Q79oZsI36kS/UR7WbPoJVXxARUxrXGX4VeJ76Swz/Q+MV20TECY03Xg5nHfDOiDi60U9/EfD3Lb7zbeAPIuJfNrbzlhHUD/Bd6m8XhV90Bw3lvwHLI+JfDWwvIn5lhNvUJGEoaDz7PNB8F9KXqf8i/j5wOvs/ih/O89R/eT8CXJmZO6lfd3gOeCoiNgG30eLIOTNfAT4OrAWeAZ7KzIdbfOdb1F+n3tvozrlmBPVD/drJhyJiPbDf6y6Ncaj/hPqoYD8AvkP9bavSfvmWVElS4ZmCJKkwFCRJhaEgSSoMBUlSYShIkgpDQZJUGAqSpMJQkCQV/x91BMOHOed6JwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Solution\n",
    "\n",
    "thinkplot.Pmf(pmf)\n",
    "thinkplot.Config(xlabel='Number of children', ylabel='PMF')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution\n",
    "\n",
    "biased = BiasPmf(pmf, label='biased')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAGXdJREFUeJzt3X+UV3W97/Hnm9/mMY8Ct6sOnuGg3ERF0BFRMDHMJE1cVww92tXUo3mzTLNz7drS8vRLszrHpf2gLO2XP8osPWFSpgc1fwBqCqKGRjpXM8RKOS7Egff9Y77svowDX5iZzXfmO8/HWiz3/u5f7z3gvPb+7O/+fCIzkSQJYEC9C5Ak9R6GgiSpYChIkgqGgiSpYChIkgqGgiSpYChIkgqGgiSpYChIkgqD6l3AlhoxYkQ2NzfXuwxJ6lMWLVr0UmaOrLVenwuF5uZmFi5cWO8yJKlPiYg/bM56Nh9JkgqGgiSpYChIkgp97pmCpMb0xhtv0NrayurVq+tdSp82bNgwmpqaGDx4cJe2NxQk9Qqtra1st912NDc3ExH1LqdPykxWrlxJa2sro0eP7tI+bD6S1CusXr2a4cOHGwjdEBEMHz68W3dbhoKkXsNA6L7u/gz7TfPRz+5fzg13P83rb6ytdyk9Yujggcw+eAwzJzfXuxRJDaTf3Ck0UiAAvP7GWm64++l6lyFpM0ybNq3mS7fXXHMNZ599NgCnnHIKP/7xj9+0zl133cVRRx1VSo3r9ZtQaKRAWK8Rz0lSffWb5qNqN/3fw+tdQrcc+7l59S5BakjLly9nxowZTJ06ld/85jfssssu/OxnP2PGjBlcfvnltLS08NJLL9HS0sLy5cu55ppr+OlPf8ratWtZvHgxH/vYx1izZg3f+973GDp0KHPnzmXHHXcs9r9u3To+8IEPMGrUKD7zmc/wne98h89//vPstNNOjB07lqFDhxbrzp8/ny9/+cv88Y9/5LLLLmPWrFkArFq1ilmzZrF48WL2228/vv/97/fos5h+GQqSercyL3xqXRT+7ne/47rrruOb3/wm73vf+7jppps2uf7ixYt5+OGHWb16NbvtthuXXnopDz/8MOeeey7f/e53+ehHPwpAW1sbJ554InvttRcXXnghL7zwAhdffDGLFi1i++2359BDD2XixInFfl944QXuuecennjiCY4++ugiFB5++GGWLFnCzjvvzJQpU7j33nuZOnVqN38qf9Nvmo8kaXOMHj2aCRMmALDffvuxfPnyTa5/6KGHst122zFy5Ei233573vve9wKw9957b7DtmWeeWQQCwAMPPMC0adMYOXIkQ4YMYfbs2Rvs95hjjmHAgAGMGzeOF198sfh80qRJNDU1MWDAACZMmFCzvi1lKEhSleomnIEDB9LW1sagQYNYt24dwJveAahef8CAAcX8gAEDaGtrK5YddNBB3HnnnRtsv6lmn+r9ZuYm6+tJNh9J6nV623O/5uZmFi1axKRJkzr9VtDmOO2005g/fz7HHXccN998MwcccADnnHMOK1eu5K1vfSs/+tGP2GeffXq48i3nnYIk1XD++efzta99jYMOOoiXXnqpy/s577zz2HfffXn/+9/P2972Nj71qU9x4IEHcthhh7Hvvvv2YMVdF9W3JX1BS0tLdmWQneoHV73tKmRLNdK5SOstXbqUPfbYo95lNITOfpYRsSgzW2pt652CJKlgKEiSCoaCJKlgKEiSCoaCJKlgKEiSCoaCJFUsX76cvfba602fn3766Tz++OOlHbe5ublb7z/0JN9olqQavvWtb9W7hK3GOwVJqtLW1sbJJ5/M+PHjmTVrFq+99toGg+ScddZZtLS0sOeee3LxxRcX211wwQWMGzeO8ePHc/755wOwYsUKjj32WPbff3/2339/7r33XgBWrlzJ4YcfzsSJEznzzDPpTS8Re6cgqde58NYnStv3Z9/79k0uf/LJJ7n66quZMmUKp556Kl/96lc33P6zn2XHHXdk7dq1TJ8+nUcffZSmpiZuvvlmnnjiCSKCv/zlLwCcc845nHvuuUydOpVnn32Wd7/73SxdupRPf/rTTJ06lYsu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QOU5wz8CT9LeieFZlS62iYixlR4vN+UB4JCIGFFppz8B+M8a28wDTo2It1SOs2MX6ge4l/beReFvzUGduQOYFRH/bf3xIuIfunhM9ROGgnqzLwHV30L6Ju2/iB8EDmDjV/Gb8iTtv7xvAz6Ymatpf+7wOPBQRCwGvkGNK+fMfAH4BHAn8Fvgocz8WY1tfkF7d+oLK80553ehfmh/dvKhiFgAbPS5S2Uc6k/SPirYo8Avae9tVdooe0mVJBW8U5AkFQwFSVLBUJAkFQwFSVLBUJAkFQwFSVLBUJAkFQwFSVLh/wPmfwEY1U1LNwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Solution\n",
    "\n",
    "thinkplot.PrePlot(2)\n",
    "thinkplot.Pmfs([pmf, biased])\n",
    "thinkplot.Config(xlabel='Number of children', ylabel='PMF')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.024205155043831"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Solution\n",
    "\n",
    "pmf.Mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.403679100664282"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Solution\n",
    "\n",
    "biased.Mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Exercise:** I started this book with the question, \"Are first babies more likely to be late?\" To address it, I computed the difference in means between groups of babies, but I ignored the possibility that there might be a difference between first babies and others for the same woman.\n",
    "\n",
    "To address this version of the question, select respondents who have at least two live births and compute pairwise differences. Does this formulation of the question yield a different result?\n",
    "\n",
    "Hint: use `nsfg.MakePregMap`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "live, firsts, others = first.MakeFrames()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "preg_map = nsfg.MakePregMap(live)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution\n",
    "\n",
    "hist = thinkstats2.Hist()\n",
    "\n",
    "for caseid, indices in preg_map.items():\n",
    "    if len(indices) >= 2:\n",
    "        pair = preg.loc[indices[0:2]].prglngth\n",
    "        diff = np.diff(pair)[0]\n",
    "        hist[diff] += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD9CAYAAAC1DKAUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAFD5JREFUeJzt3X+M5PV93/Hnq3cGxzjO8WNx8d25nJOzXWqlNd1gWrcWNTa/bHFUMhLICleH6tQUHKe0MlCioMaxZCdVcFFSrKu5GiQCJsQpV5cUXzAUVSo/Dhtj4IxZ45TbQLizDkhSFJyz3/1jPhdPjr3dvZ3dnYXP8yGN5vt9fz8z8x72mNd8vt/vzKSqkCT152+NuwFJ0ngYAJLUKQNAkjplAEhSpwwASeqUASBJnZozAJJsS7InyaMH1T+e5IkkjyX5jaH6lUmm2rYzh+pntdpUkisW92lIkg5X5vocQJL3AX8B3FhV72q1fwZcBXyoql5OcnxV7UlyEnAzcArwFuCPgLe3u/oO8EFgGngQuLCqHl+C5yRJmofVcw2oqnuTnHhQ+ReBz1TVy23MnlbfBNzS6t9LMsUgDACmquopgCS3tLEGgCSNyUKPAbwd+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qUASBJnTIAJKlTBoAkdcoAkKROGQCS1CkDQJI69f8B/PJrQc+VO60AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Solution\n",
    "\n",
    "thinkplot.Hist(hist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.056367432150313125"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Solution\n",
    "\n",
    "pmf = thinkstats2.Pmf(hist)\n",
    "pmf.Mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Exercise:** In most foot races, everyone starts at the same time. If you are a fast runner, you usually pass a lot of people at the beginning of the race, but after a few miles everyone around you is going at the same speed.\n",
    "When I ran a long-distance (209 miles) relay race for the first time, I noticed an odd phenomenon: when I overtook another runner, I was usually much faster, and when another runner overtook me, he was usually much faster.\n",
    "\n",
    "At first I thought that the distribution of speeds might be bimodal; that is, there were many slow runners and many fast runners, but few at my speed.\n",
    "\n",
    "Then I realized that I was the victim of a bias similar to the effect of class size. The race was unusual in two ways: it used a staggered start, so teams started at different times; also, many teams included runners at different levels of ability.\n",
    "\n",
    "As a result, runners were spread out along the course with little relationship between speed and location. When I joined the race, the runners near me were (pretty much) a random sample of the runners in the race.\n",
    "\n",
    "So where does the bias come from? During my time on the course, the chance of overtaking a runner, or being overtaken, is proportional to the difference in our speeds. I am more likely to catch a slow runner, and more likely to be caught by a fast runner. But runners at the same speed are unlikely to see each other.\n",
    "\n",
    "Write a function called `ObservedPmf` that takes a `Pmf` representing the actual distribution of runners’ speeds, and the speed of a running observer, and returns a new `Pmf` representing the distribution of runners’ speeds as seen by the observer.\n",
    "\n",
    "To test your function, you can use `relay.py`, which reads the results from the James Joyce Ramble 10K in Dedham MA and converts the pace of each runner to mph.\n",
    "\n",
    "Compute the distribution of speeds you would observe if you ran a relay race at 7 mph with this group of runners."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "import relay\n",
    "\n",
    "results = relay.ReadResults()\n",
    "speeds = relay.GetSpeeds(results)\n",
    "speeds = relay.BinData(speeds, 3, 12, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3XuYVNWZ7/HvT67eMILtJAEzTQZiBhERm1ZPEsdIoni8YIJGjEnUOGHMSETz6IiZR8cxyTPjmZzD8TYSEhgvYwQfHA8cRVBHHXNBpBkRReKkQ1AacmLjBS8RFXnPH7UbirKqq7qrd1dV1+/zPP3Urr3XXntVaffLevfaaykiMDMz6669Kt0AMzOrbQ4kZmZWFgcSMzMriwOJmZmVxYHEzMzK4kBiZmZlcSAxM7OyOJCYmVlZHEjMzKws/SvdgN5w0EEHRWNjY6WbYWZWU1avXr01IhqKlauLQNLY2EhLS0ulm2FmVlMkvVhKOae2zMysLA4kZmZWFgcSMzMrS13cIzGzynn//fdpa2tj+/btlW6KFTB48GBGjBjBgAEDunW+A4mZpaqtrY3999+fxsZGJFW6OZYjInjllVdoa2tj5MiR3aoj1dSWpMmSXpDUKmlWnuODJC1Mjq+U1Jhz/BOS3pJ0eal1mll12b59O8OGDXMQqVKSGDZsWFk9xtQCiaR+wC3AycAY4BxJY3KKXQi8FhGjgNnA9TnHZwMPdrFOM6syDiLVrdz/PmmmtpqB1ojYACBpATAFeD6rzBTg2mR7EXCzJEVES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5KGHHmLJkiX86Ec/AjLDq1966SWeeOIJLrnkEgDGjRvHuHHjAPjkJz/Jhg0b+M53vsMpp5zCiSee2KXPWYpUH0iMiKXA0px912RtbwfOKlLHtcXqNDMr5PHHH+eRRx5hxYoV7LPPPhx//PFs376diChp2Gv//v3ZuXMnkAke7733HgB33XUX7e3trF69mgEDBtDY2Njpsxif+tSnWL16NUuXLuWqq67ixBNP5JprMn8Os9vRsb1z505WrFjB3nvvvUc9EcG9997LoYce+qFr5Ps8Bx54IM888wzLly/nlltu4Z577mH+/PlFP3dX+Ml2M+s1naWf0rJt2zYOPPBA9tlnH37961/z5JNPAnDsscdy8cUX87vf/W6P1Nb+++/PG2+8sev8xsZGVq9ezVe+8hUWL17M+++/v6vegw8+mAEDBvDYY4/x4oudz7i+ZcsWhg4dyte+9jX2228/brvttl3HFi5cyKxZs1i4cCHHHnssACeeeCI333wzV1xxBZBJUY0fP56TTjqJm266iZtuuglJPP300xx55JEcd9xx3HXXXXz+85/nueeeY+3atQBs3bqVgQMHMnXqVP7sz/6M888/v6e+2l0cSMysT5s8eTJz5sxh3LhxHHrooRxzzDEANDQ0MHfuXL785S+zc+dODj74YB5++GFOO+00zjzzTBYvXsxNN93Et771LaZMmUJzczOTJk1i3333BeDcc8/ltNNOo6mpifHjx/PpT3+603Y8++yzXHHFFey1114MGDCAW2+9ddexd999l6OPPpqdO3dy9913A5l03MUXX8y4cePYsWMHxx13HHPmzOHqq6/m0ksvZdy4cUQEjY2N3H///Xz729/mggsuYNy4cYwfP57m5mYANm/ezAUXXLCrV/UP//APPf4dK3Nvu29ramoKL2zV9xW6kVuJfwXbbuvXr+fP//zPK92MqtWx8N5BBx1U0Xbk++8kaXVENBU71z0Sq1t+Et6sZ3g9EqtbfhLeqsHGjRsr3hsplwOJ1S0/Cd976iGFXsvK/e/jQGJmqRo8eDCvvPKKg0mV6liPZPDgwd2uw/dIzCxVI0aMoK2tDc95V706VkjsLgcSM0vVgAEDur3yntUGBxKrabkjr8ys9/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ICK2RsQWAEkbJV0v6ankZ1Syv0HSvZJWJT+fSfbvm6wRsSqZYHJKsn9vSQuSHs9CYO8CbTmXrKeyJb2VXH+1pEckNSe9mQ2STk/KnC9psaRlkl6Q9HdZ9fWT9JOkt/WQpL2Tz/giMEzSR3vyi7T65UBi9e4h4BBJ/yXpnyX9Rc7xNyKiGbiZzIzMkFkfZXZETASmsnuq/78lM53NRODzwD8lMxV/G/hjskbED4GjCrTlM0D2RJ37Ao9HxFHAm8APgC8CXwKuyyrXTCYIjQfOykqbjQZuiYjDgNeTtnb4z+R6ZmVzasvqWkS8Jeko4HNk/vgvlDQrIm5Lityd9To72f4CMCaZggJgiKT9gRPJTLZ5ebJ/MPAJMuup3Jhcb62ktQWa8zEyU+Z3eA9Ylmw/C7wbEe9LehZozCr3cES8AiDp34DPAv+HzASPa5Iyq3POeZnMDMJmZXMgsboXER8AjwOPJ3+kzyOz+hxA9hxCHdt7AcdGxDvZ9SQTKU6NiBdy9ufWU8g7ZIJPh/ezZm/dCXSk33YmC1vltiv3/btZ+z5gz5Ta4OR6ZmVzasvqmqRDJY3O2jUeeDHr/dlZryuS7YeAGVl1jE82lwPfSQIKko5M9j9BJvWEpLHAuALNWQ+M6sbH+GKybvneZFYH/GUJ53wKyDuqy6yrHEis3u0H3C7p+STlNAa4Nuv4IEkrgZnAZcm+S4Cm5Ob580DH7KrfBwYAa5Oht99P9t8K7JfU/zfAUwXa8gCZ2Vy76hfAncAa4N6IaOmssKQBZAJWp+XMSuXZf80KSBYWa4qIrb10vb2Bx4DPJOm2Us45n0wbZxQrm3XOl8gMd766Ww01y+EeiVmVSO65/B0wPOVL9Qf+Z8rXsDriHomZmZXFPRIzMyuLA4mZmZXFgcTMzMriQGJmZmVxIDEzs7I4kJiZWVn+P3FaNcarpGamAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "pmf = thinkstats2.Pmf(speeds, 'actual speeds')\n",
    "thinkplot.Pmf(pmf)\n",
    "thinkplot.Config(xlabel='Speed (mph)', ylabel='PMF')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution\n",
    "\n",
    "def ObservedPmf(pmf, speed, label=None):\n",
    "    \"\"\"Returns a new Pmf representing speeds observed at a given speed.\n",
    "\n",
    "    The chance of observing a runner is proportional to the difference\n",
    "    in speed.\n",
    "\n",
    "    Args:\n",
    "        pmf: distribution of actual speeds\n",
    "        speed: speed of the observing runner\n",
    "        label: string label for the new dist\n",
    "\n",
    "    Returns:\n",
    "        Pmf object\n",
    "    \"\"\"\n",
    "    new = pmf.Copy(label=label)\n",
    "    for val in new.Values():\n",
    "        diff = abs(val - speed)\n",
    "        new[val] *= diff\n",
    "    new.Normalize()\n",
    "    return new\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAHz1JREFUeJzt3XuUVOWZ7/HvE+4X0RxkzuSAiFkQjkjaBhoIB7yhcsl46Bgw3VFHiLhQjyTEs2QGk0U0JlmD0RPiLUFHjKBR8A4xGkmGSZQsojQjMiIaCBBszCSIihfk0vKcP2p3UxRVvau6a9euy++zVq+u2vVW7acLqp793s3dERERac2n4g5ARESKn5KFiIiEUrIQEZFQShYiIhJKyUJEREIpWYiISCglCxERCaVkISIioZQsREQkVMe4A8iXE0880QcMGBB3GCIiJWX9+vVvu3ufsHJlkywGDBhAQ0ND3GGIiJQUM/tzNuXUDCUiIqGULEREJJSShYiIhCqbPgsRab9Dhw7R2NjI/v374w5F8qxr167069ePTp06ten5ShYi0qKxsZHjjjuOAQMGYGZxhyN54u7s2bOHxsZGTjnllDa9hpqhRKTF/v376d27txJFmTEzevfu3a4ao5KFiBxFiaI8tfffVc1QEqkVq19h+bMNHDh4CIAunTtRN7mG2vGnxxyZiORCNQuJVHKiADhw8BDLn9XkScnNjh07GDp0aNxhHOPss8+OfTLwjTfeyK233hr5eZQsJFLJiaK1YyKF1tTUFHcIJUXJQkSKyo9+9COGDh3K0KFD+fGPf9xyvKmpienTp1NVVcW0adPYt28fAPPmzWPIkCFUVVVx3XXXAbB7926mTp3KyJEjGTlyJL///e+BxFX4rFmzmDBhApdddhmjR49m06ZNLec4++yzWb9+PR999BGXX345I0eOZNiwYaxYsQKAjz/+mPr6eqqqqqirq+Pjjz9O+zeki2nGjBlcddVVnHHGGXzuc5/j6aefBuCTTz5h7ty5jBw5kqqqKu6+++6W17nllltajt9www0tx3/wgx8wePBgzjvvPN54442W47fffnvLeevr69v+j5BGpH0WZjYJuA3oANzr7gtSHu8CLAVGAHuAOnffkfR4f+A14EZ3j76eJSItps5ZFNlrP37bVWmPr1+/np/97Ge8+OKLuDujR4/mrLPO4tOf/jRvvPEGixcvZuzYsVx++eX85Cc/4fLLL+fJJ5/k9ddfx8x47733AJgzZw7XXnst48aNY+fOnUycOJHNmze3nGPNmjV069aNhQsX8sgjj/Dd736Xv/zlL7z11luMGDGCb33rW4wfP5777ruP9957j1GjRnHeeedx99130717dzZu3MjGjRsZPnz4MX/DO++8kzYmSDSn/e53v+NPf/oT55xzDlu3bmXp0qUcf/zxrFu3jgMHDjB27FgmTJjAli1b2LJlCy+99BLuzpQpU3j++efp0aMHy5Yt4+WXX6apqYnhw4czYsQIABYsWMD27dvp0qXLUefNh8hqFmbWAbgLmAwMAb5qZkNSis0E3nX3gcBC4OaUxxcCz0YVo4gUlzVr1nDhhRfSo0cPevbsyZe//GVeeOEFAE466STGjh0LwKWXXsqaNWvo1asXXbt25Yor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CfBb4LfBF/F0EjuRASSve9N8+1PAGHf/OPl1gsX9prr7GynHU18nk49JJJhmh5JWDj0MNDeVHQ42P0qNK/X+gaRjn3B081fX4Hwi7aJmKKkIZjbYzAYlHaoG/px0vy7p99rg9ipgdtJrVAc3nwO+HiQNzGxYcPx5Es1EmNlQoCpDOJuBgW34M84P9qLuRmKnuN9n8ZzPAWlHS4nkQslCKkVPYImZvRY0Dw0Bbkx6vIuZvUhiP/Rrg2PfAGqCDuvXgOaVPb8HdAI2BsNWvxcc/ynQM3j9fwJeyhDLL0msJJqrNcADwAbgcXdvaK2wmXUikZRaLSeSDa06KxUv2Hyqxt3fLtD5ugH/DowNmsayec4MEjHODiub9JwLSQwVnt+mQEWSqGYhUmBBH8gNQN+IT9UR+H8Rn0MqhGoWIiISSjULEREJpWQhIiKhlCxERCSUkoWIiIRSshARkVBKFiIiEur/A8Smpxc85ZeVAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Solution\n",
    "\n",
    "biased = ObservedPmf(pmf, 7, label='observed speeds')\n",
    "thinkplot.Pmf(biased)\n",
    "thinkplot.Config(xlabel='Speed (mph)', ylabel='PMF')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
